<template>
	<!-- 专业列表 -->
	<view class="wm">
		<block v-if="major_list.length > 0">
			<navigator hover-class="none" class="school" v-for="(item,i) in major_list" :key="i" :url="'/subpkg/major_detail/major_detail?id='+item.id">
				<view class="school_info">
					<view class="school_name">{{item.name}}</view>
				</view>
				<view class="right">
					<uni-icons type="right" color="#515151"></uni-icons>
				</view>
			</navigator>
		</block>
		<block v-else>
			<no-data></no-data>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				require:{
					pageNumber:1,
					length:10
				},
				border:true,
				isloading:false,
				total:1,
				major_list:[]
			};
		},
		onLoad(){
			this.get_major_list()
		},
		methods:{
			/**
			 * 获取所有的专业列表
			 */
			async get_major_list(){
				//打开节流阀
				this.isloading = true
				//请求接口
				const {data:res} =  await uni.$http.post("Schools/getAllMajor",this.require)
				//关闭节流阀
				this.isloading = false
				//判断请求接口是否失败，如果失败弹出消息
				if(res.meta.status == 0) return uni.$showMsg()
				//追加数据
				this.major_list = [...this.major_list,...res.data]
				//当前数据的总页数
				this.total = res.total
			},
			/**
			 * 跳转到专业介绍页面
			 */
			major_detail(index){
				uni.navigateTo({
					url:"/subpkg/major_detail/major_detail?id="+this.major_list[index].id
				})
			},
			/**
			 * 上拉列表的时候加载更多
			 */
			onReachBottom(){
				//根据节流阀加载数据
				if(this.isloading) return 
				this.require.pageNumber++
				if(this.require.pageNumber <= this.total){
					this.get_major_list();
				}
			}
		}
	}
</script>

<style lang="scss">
@import "../../static/list.scss";
</style>
